package view;

import java.awt.Graphics;

import model.Model;
import util.MyPosition;

public class BloodView extends ModelView {
    private double mode; // 血条百分比

    public BloodView(MyPosition position, Model model) {
        super(position, model);
        setPosition(position);
        mode = 1;
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        g.setColor(color);
        int w = (int) (position.getWidth() * mode);
        setBounds(position.getX(), position.getY() - position.getHeight(), position.getWidth(), position.getHeight());
        g.drawRect(0, 0, position.getWidth() - 1, position.getHeight() - 1);
        g.fillRect(0, 0, w, position.getHeight());
    }

    @Override
    public void stay() {
        // 血条不需要待在原地
    }

    // set&get
    @Override
    public void setPosition(MyPosition position) {
        this.position = new MyPosition(position);
        this.position.setHeight(this.position.getHeight() / 3);
        repaint();
    }

    public double getMode() {
        return mode;
    }

    public void setMode(double mode) {
        this.mode = mode;
        repaint();
    }

}
